package durst.action.account;

import java.sql.SQLException;
import java.util.List;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.validation.ValidateNestedProperties;
import durst.action.CalendarBasicAction;
import durst.data.UserCalendar;
import durst.data.dao.DaoFactory;
import durst.data.dao.impl.UserCalendarDao;

public class DeleteCalendarAction extends CalendarBasicAction {
	@ValidateNestedProperties(@Validate(field = "id", required = true))
	private List<UserCalendar> cals;

	@SuppressWarnings("unchecked")
	@DefaultHandler
	public Resolution handle() throws SQLException {
		((UserCalendarDao<UserCalendar, Integer>) DaoFactory.getInstance().createDao(
				UserCalendar.class)).deleteCalendars(context.getAccount(), cals);
		return new RedirectResolution(ManageAccountActionBean.class);
	}

	public void setCals(List<UserCalendar> cals) {
		this.cals = cals;
	}

	public List<UserCalendar> getCals() {
		return cals;
	}
}
